import { defineStore } from "pinia"
import { reqC1List,reqC2List,reqC3List } from '@/api/product/attr/attr'
let useCategoryStore = defineStore('category', {
    state: () => {
        return {
            //存储一级分类的数据
            c1List: [],
            //存储二级分类的数据
            c2List: [],
            //存储三级分类的数据
            c3List: [],
            c1Id:'',
            c2Id:'',
            c3Id:'',

        }
    },
    actions: {
        //一级接口
        async getC1List() {
            let result = await reqC1List()
            this.c1List=result
           
        },
        //二级接口
        async getC2List() {
            this.c2Id='';
            this.c3Id='';
            this.c2List=[];
            this.c3List=[];
            //存储三级分类的数据
            let result = await reqC2List(this.c1Id)
            this.c2List=result
            
        },

        //三级接口
        async getC3List() {
            this.c3Id='';
            this.c3List=[];
            let result = await reqC3List(this.c2Id)
            this.c3List=result
            
        },


    }
})
export default useCategoryStore 
